package com.hanxiaozhang;

import com.hanxiaozhang.exception.DistributedLockException;

import java.util.concurrent.TimeUnit;

/**
 * 功能描述: <br>
 * 〈分布式锁抽象类〉
 *
 * @Author:hanxinghua
 * @Date: 2022/8/29
 */
public abstract class AbstractDistributedLock implements DistributedLock {

    /**
     * 锁key
     */
    protected String lockKey;


    public AbstractDistributedLock() {
        lockKey = "default_lock";
    }


    public AbstractDistributedLock(String lockKey) {
        this.lockKey = lockKey;
    }

    @Override
    public String getLockKey() {
        return this.lockKey;
    }

    @Override
    public void lock() throws DistributedLockException {

        throw new DistributedLockException("不支持此操作！");
    }

    @Override
    public void lockInterruptibly() throws DistributedLockException, InterruptedException {

        throw new DistributedLockException("不支持此操作！");
    }

    @Override
    public Boolean tryLock() throws DistributedLockException {

        throw new DistributedLockException("不支持此操作！");
    }

    @Override
    public Boolean tryLock(long time, TimeUnit unit) throws DistributedLockException, InterruptedException {

        throw new DistributedLockException("不支持此操作！");
    }

    @Override
    public void unlock() throws DistributedLockException {

        throw new DistributedLockException("不支持此操作！");
    }

}
